package com.jinjiafeng.framelibrary.skin.attr;

import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jinjiafeng.framelibrary.skin.SkinManager;
import com.jinjiafeng.framelibrary.skin.SkinResource;

/**
 * Created by jinjiafeng.
 * date:on 18-5-9
 */

public enum  SkinType {

    TEXT_COLOR("textColor") {
        @Override
        public void skin(String resName, View view) {
            ColorStateList color = getSkinResource().getColorByName(resName);
            if(color!=null){
                TextView textView = (TextView) view;
                textView.setTextColor(color);
            }
        }
    },
    BACKGROUND("background") {
        @Override
        public void skin(String resName, View view) {
            Drawable drawable = getSkinResource().getDrawableByName(resName);
            if(drawable!=null){
                view.setBackground(drawable);
                return;
            }
            //有可能是颜色背景
            ColorStateList color = getSkinResource().getColorByName(resName);
            if(color!=null){
                view.setBackgroundColor(color.getDefaultColor());
            }
        }
    },
    SRC("src") {
        @Override
        public void skin(String resName, View view) {
            Drawable drawable = getSkinResource().getDrawableByName(resName);
            if(drawable!=null){
                ImageView imageView = (ImageView) view;
                imageView.setImageDrawable(drawable);
            }
        }
    };

    private final String mType;

    SkinType(String type) {
        mType = type;
    }

    public String getType() {
        return mType == null ? "" : mType;
    }

    public SkinResource getSkinResource(){
        return SkinManager.getInstance().getSkinResource();
    }

    public abstract void skin(String resName, View view);
}
